package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.UserInfo;
import com.itheima.mapper.UserInfoMapper;
import com.itheima.service.db.UserInfoService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service // dubbo的
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public void save(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    @Override
    public UserInfo findByUserId(Long userId) {
        return userInfoMapper.selectById(userId);
    }

    // 分页查询用户列表
    @Override
    public PageBeanVo findUserInfoByPage(Integer pageNum, Integer pageSize) {
        // 1.开启分页
        IPage page = new Page(pageNum, pageSize);

        // 2.分页查询
        page = userInfoMapper.selectPage(page, null);

        // 3.返回自定义分页对象
        return new PageBeanVo(pageNum, pageSize, page.getTotal(), page.getRecords());
    }
}
